import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import a003 from './a003';

export default async function a005(fd: IFeidaoAiBrowserComponent, args: { currentTarget: { children: {} } }) {
	// 排序

	const node = args.currentTarget.children[0] as HTMLLIElement;
	const sort = node.getAttribute('sort');
	const name = node.getAttribute('name');
	const nodes = fd.data.node.querySelectorAll<HTMLSpanElement>('[paixu]');
	const asc = new Array();
	const desc = new Array();
	if (sort === 'z') {
		node.setAttribute('sort', 'd');
		node.classList.add('icon-shang');
		node.classList.remove('icon-xia');
		node.classList.remove('icon-shangxia');
		asc.push(name);
		set(fd, 'asc', asc);
		set(fd, 'desc', []);
		await a003(fd);
	}
	if (sort === 'd') {
		node.setAttribute('sort', 'z');
		node.classList.add('icon-xia');
		node.classList.remove('icon-shang');
		node.classList.remove('icon-shangxia');
		desc.push(name);
		set(fd, 'asc', []);
		set(fd, 'desc', desc);
		await a003(fd);
	}
	Array.from(nodes).map((v) => {
		const name1 = v.getAttribute('name');
		if (name1 !== name) {
			v.setAttribute('sort', 'z');
			v.classList.add('icon-shangxia');
			v.classList.remove('icon-xia');
			v.classList.remove('icon-shang');
		}
	});
}
